﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.freegiftsale {
    import Display.DialogUI.*;
    import Modules.stats.experiments.*;
    import Modules.freegiftsale.ui.*;

    public class FreeGiftSaleManager {

        public static const DEFAULT_COOLDOWN:int = 7200;
        public static const DEFAULT_MIN_LEVEL:int = 6;
        public static const ACTIVATION_FLAG:String = "freeGiftSale_lastSeen";
        public static const VAR_NOTIF_COOLDOWN:String = "freeGiftSaleNotifCooldown";
        public static const VAR_MINLEVEL:String = "freeGiftMinLevel";

        public static var endDate:Number = -1;

        protected var m_variant:int = 0;
        protected var m_coolDownPeriod:int = -1;
        protected var m_minLevel:int = 0;
        private var m_sales:Array;

        public function FreeGiftSaleManager(){
            this.m_sales = new Array();
            super();
            this.init();
            var _local1:int;
        }
        public function get saleVariant():int{
            return (this.m_variant);
        }
        public function canShowSale(_arg1:Boolean=true):Boolean{
            var _local2:Number = new Date().getTime();
            var _local3:Boolean = ((!(Global.player.isNewPlayer)) && ((Global.player.level >= this.m_minLevel)));
            var _local4 = (this.m_variant > 0);
            var _local5:Boolean = (((_arg1 == false)) || ((this.isCooldownActive == false)));
            var _local6 = (_local2 > FreeGiftSaleManager.endDate);
            return (((((((((_local3) && (_local4))) && (_local5))) && (!(_local6)))) && ((this.getSales().length > 0))));
        }
        public function get isCooldownActive():Boolean{
            var _local1:int = (GlobalEngine.getCurrentTime() / 1000);
            return (((_local1 - FreeGiftSaleManager.DEFAULT_COOLDOWN) <= Global.player.getLastActivationTime(ACTIVATION_FLAG)));
        }
        public function get hasPurchased():Boolean{
            return (Global.player.getSeenFlag("free_gift_purchase"));
        }
        public function init():void{
            this.m_variant = Global.experimentManager.getVariant(ExperimentDefinitions.EXPERIMENT_FREEGIFTSALE);
            this.m_coolDownPeriod = Global.gameSettings.getInt(VAR_NOTIF_COOLDOWN, DEFAULT_COOLDOWN);
            this.m_sales = Global.gameSettings.getFreeGiftSaleData();
            this.m_minLevel = Global.gameSettings.getInt(VAR_MINLEVEL, DEFAULT_MIN_LEVEL);
        }
        public function getStartupDialog():GenericDialog{
            return (new FreeGiftSaleDialog("", "FreeGiftSale", GenericDialogView.TYPE_MODAL, this.onCloseStartup, "", "", true, 0, "", this.onCloseStartup, ""));
        }
        public function getSales():Array{
            if (((!(this.m_sales)) || ((this.m_sales.length == 0)))){
                return (new Array());
            };
            return (this.m_sales[0].featuredSales);
        }
        private function onCloseStartup(_arg1=null):void{
            Global.player.setLastActivationTime(ACTIVATION_FLAG, GlobalEngine.getCurrentTime());
        }

    }
}//package Modules.freegiftsale 
